package net.bwie.realtime.jtp.dim.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;

import java.util.HashMap;

/**
 * @Author: FuHe
 * @Date: 2025/6/2
 */
public class HbaseDimMapFunction extends RichMapFunction<String, String> {
     private HashMap<String, String> dimMap;
    public HbaseDimMapFunction(HashMap<String, String> dimMap) {
        this.dimMap = dimMap;
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public String map(String value) throws Exception {
        // 解析json格式
         JSONObject jsonObject = JSON.parseObject(value);
         // 添加 Hbase表名
        jsonObject.put("hbase_table_name","dim_"+ jsonObject.getString("table_name"));
        // 添加列簇名称
        jsonObject.put("family_name","info");
        // 添加rowkey值对应的字段名称
        jsonObject.put("row_key_column",dimMap.get(jsonObject.getString("table_name")));
        return jsonObject.toJSONString();
    }

    @Override
    public void close() throws Exception {
        super.close();
    }
}
